<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
<script type="text/javascript">
    var searchProperty = "<?php echo $searchProperty;?>";
    var searchField = "<?php echo $searchField;?>";
    var searchText = "<?php echo $searchText;?>";
    function checkAll() {
        var checkall = document.getElementsByName('check_all');
        for (var i = 0; i < checkall.length; i++) {
            checkall[i].checked = true;
        }
    }
    function checkInvert() {
        var checkall = document.getElementsByName('check_all');
        for (var i = 0; i < checkall.length; i++) {
            if (checkall[i].checked)
                checkall[i].checked = false;
            else
                checkall[i].checked = true;
        }
    }


    function actionFun(content, actionType) {
        var confirmResult = false;
        //if(content == null && actionType)
        switch (actionType) {
            case "delete":
                confirmResult = confirm('确定要删除？');
                break;
            case "publish":
                confirmResult = confirm('确定要发布？');
                break;
            case "cancelPublish":
                confirmResult = confirm('确定要取消发布？');
                break;
        }
        if (actionType == "search")
            confirmResult = true;
        if (confirmResult) {
            if (1 == content && actionType != "search") {
                var checkall = document.getElementsByName('check_all');
                content = "";
                for (var i = 0; i < checkall.length; i++) {
                    if (checkall[i].checked)
                        content += checkall[i].value + " ";
                }
            }
            if (actionType == "search") {
                if ($("#sSearchProperty").val() != "none")
                    content += "/searchProperty/" + $("#sSearchProperty").val();
                if ($("#sSearchField").val() != "none")
                    content += "/searchField/" + $("#sSearchField").val();
                var searchCondition = $.trim($("#txtSearch").val());
                if (searchCondition != "") {
                    content += "/searchText/" + searchCondition;
                }
            }
            var nowurl=window.location;
            window.location = "<?php echo url_for("comment/indexn?submitType=");?>" + actionType + "/content/" + content;
            switch (actionType) {
                case "delete":
                case "publish":
                case "cancelPublish":
                    window.location=nowurl;
                    break;
            }
        }
    }

    function editInfo(content) {
        location = "<?php echo url_for("comment/edit?contentEdit=1&content=");  ?>" + content;
    }

    $(document).ready(function() {
        if (searchProperty != "")
            $("#sSearchProperty").val(searchProperty);
        if (searchField != "")
            $("#sSearchField").val(searchField);
        $("#txtSearch").val(searchText);
    });
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-right:10px;">
    <tr>
        <td style="height:30px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>位置：<?php echo $navigator;?></td>
                    <td></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td style="height:30px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <input id="del" type="button" onclick="actionFun(1,'delete');" value="删除评论"/></td>
                    <td align="right">搜索：
                        <select name="sSearchProperty" id="sSearchProperty" onchange="actionFun(null,'search')">
                            <option value="none">不限属性</option>
                            <option value="publish">发布</option>
                            <option value="unexamined">不审核</option>
                            <option value="delete">删除</option>
                        </select>
                        <input name="txtSearch" type="text" id="txtSearch"/>
                        <select name="sSearchField" id="sSearchField" onchange="actionFun(null,'search')">
                            <option value="none">不限字段</option>
                            <option value="cid">评论Id</option>
                            <option value="tid">标题Id</option>
                            <option value="titles">标题</option>
                            <option value="bodys">评论内容</option>
                            <option value="name">用户名</option>
                        </select>
                        <input name="btnSearch" type="button" id="btnSearch" value="搜索"
                               onclick="actionFun(null,'search')"/></td>
                </tr>
            </table>

        </td>
    </tr>
    <tr>
        <td>
        <?php
        echo "<table cellspacing=0' cellpadding='4' border='1' style=\"width:100%;color:#333333;border-collapse:collapse;\">
        <tr style=\"color:White;background-color:#5D7B9D;font-weight:bold;height:25px;\">
        <td style=\"width:50px;\" align=\"center\">ID</td>
        <td style=\"width:30px;\" align=\"center\">选择</td>
        <td align=\"center\">标题</td>
        <td style=\"width:300px;\" align=\"center\">评论内容</td>
        <td style=\"width:100px;\" align=\"center\">发布者</td>
        <td style=\"width:100px;\" align=\"center\">发布时间</td>
        <td style=\"width:100px;\" align=\"center\">IP</td>
        <td style=\"width:70px;\" align=\"center\">状态</td>
        <td style=\"width:70px;\" align=\"center\">操作</td>
        <td align='center' style=\"width:40px;\">预览</td></tr>";
        $comments = @$pages->getResults();
        use_helper("gettitle");
        $i = 0;
        foreach ($comments as $row => $comment)
        {
            if ($i % 2 == 0)
                $trStyle = "style=\"color:#333333;background-color:#F7F6F3;height:30px;\"";
            else
                $trStyle = "style=\"color:#284775;background-color:White;height:30px;\"";
            $typeName="";
            $typeId="id";
            $editN="content";
            $edits="Edit";
            switch($comment->getContentTypeI()){
                case "1000":
                    $typeName="news";
                    $editN="id";
                    $edits="edit";
                    break;
                case "1002":
                    $typeName="celebrity";
                    $typeId="celebrityId";
                    $edits=$typeName."Edit";
                    break;
                case "1003":
                    $typeName="album";
                    $typeId="photoGroupId";
                    $edits=$typeName."Edit";
                    break;
                case "1004":
                    $typeName="magzine";
                    break;
                case "1005":
                    $typeName="music";
                    break;
                case "1001"://视频
                case "1006"://视频组
                    $typeName="video";
                    $typeId="videoId";
                    $edits=$typeName."Edit";
                    break;
            }
            echo "<tr " . $trStyle . ">
            <td>" . $comment->getCommentId() . "</td>
            <td align=\"center\"><input type='checkbox' name='check_all' value='". $comment->getCommentId() . "' /></td>
            <td>".link_to(getTitle($comment->getContentTypeI(),$comment->getContentId()),$typeName.'/edit?'.$edits.'=1&'.$editN.'='.$comment->getContentId(),'')."</td>
            <td>" . $comment->getBody() . "</td>
            <td>".$comment->getUsers()->getName()."</td>
            <td align=\"center\">" . date('Y/m/d', strtotime($comment->getCreate_time())). "</td>
            <td>" . $comment->getUserIp(). "</td>
            <td>" . $comment->getStatus()->getName(). "</td>
            <td align=\"center\"><img border='0' title='编辑' src='/sfDoctrinePlugin/images/edit.png'onclick='editInfo(" . $comment->getCommentId() . ");' style='cursor:pointer;' />"
            . "<img border='0' title='删除' src='/sfDoctrinePlugin/images/delete.png'onclick='actionFun(" . $comment->getCommentId() . ",\"delete\");' style='cursor:pointer;' /></td>
            <td align='center'><a href='/index.php/".$typeName."/detail?".$typeId."=" . $comment->getContentId() . "' target='_blank'>预览</a></td></tr>";
            $i++;
        }
        echo "</table>";
        $numPages = $pages->getLastPage();
        $CurrentPageID = $pages->getPage();
        if (@$pages->haveToPaginate()) {
            $str = $CurrentPageID - 6;
            $end = $CurrentPageID + 5;
            if ($str < 0)
                $str = 0;
            if ($end > $numPages)
                $end = $numPages;
            $catalogStr = "";
            $ords=0;
            switch($searchProperty)
            {
                case "unexamined":
                case "publish":
                case "delete":
                    $catalogStr.="&searchProperty=" . $searchProperty;
                    $ords++;
                    break;
            }
            switch($searchField)
            {
                case "titles":
                case "bodys":
                case "name":
                case "tid":
                $catalogStr.="&searchField=" . $searchField;
                if(!empty($searchText))
                    $catalogStr.="&searchText=" . $searchText;
                $ords++;
                break;
            }
            if($ords>0)
                $catalogStr .="&submitType=search";
            echo "<div class='page_list'>";
            if ($CurrentPageID > 1)
                echo link_to("首页", "comment/indexn?currentPage=1" . $catalogStr) . link_to("上一页", "comment/indexn?currentPage=" . ($CurrentPageID - 1) . $catalogStr );

            for ($i = $str; $i < $end; $i++)
            {
                if ($i == ($CurrentPageID - 1)) {
                    echo "<a class='now02' href='#'>" . ($i + 1) . "</a>";
                }
                else {
                    echo link_to(($i + 1), "comment/indexn?currentPage=" . ($i + 1) . $catalogStr );
                }
            }

            if ($CurrentPageID < $numPages)
                echo link_to("下一页", "comment/indexn?currentPage=" . ($CurrentPageID + 1) . $catalogStr ) . link_to("末页", "comment/indexn?currentPage=" . $numPages . $catalogStr );
            echo "</div>";
        }
        ?>
        </td>
    </tr>
    <tr>
        <td valign="middle" style="height:30px;">
            <input type='button' onclick='checkAll();' value='全选'/> <input type='button' onclick='checkInvert();'
                                                                           value='反选'/> <input type='button'
                                                                                               onclick='actionFun(1,"publish");'
                                                                                               value='发布'/> <input
                type='button' onclick='actionFun(1,"cancelPublish");' value='取消发布'/></td>
    </tr>
    <tr>
        <td>

        </td>
    </tr>
</table>
